package Thread.Demo8Yield;

import java.lang.Exception;

/**
 * @Author wangzhipeng
 * @Date 2020-08-10 5:35 下午
 * @Description 测试礼让
 *  礼让不一定成功 看CPU心情
 */
public class TestYield {


    public static void main(String[] args) {
        new Thread(new MyYield(),"a").start();
        new Thread(new MyYield(),"b").start();

    }

}

class MyYield implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        Thread.yield();//礼让 类静态方法
        System.out.println(Thread.currentThread().getName()+"线程停止执行");
    }
}
